New function to walk through a model in a depth first manner, with the
authorJonathan Blandford <jrb@redhat.com>
Fri, 29 Jun 2001 04:19:30 +0000 (04:19 +0000)
committerJonathan Blandford <jrb@src.gnome.org>
Fri, 29 Jun 2001 04:19:30 +0000 (04:19 +0000)
Fri Jun 29 00:13:34 2001  Jonathan Blandford  <jrb@redhat.com>

* gtk/gtktreemodel.c (gtk_tree_model_foreach): New function to
walk through a model in a depth first manner, with the option to
break out.

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtktreemodel.c
gtk/gtktreemodel.h

index f91763772016bd877553388bf48f3db8b86b21fd..f557ba76fbebdd7443031dbf934c8af23064859d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Fri Jun 29 00:13:34 2001  Jonathan Blandford  <jrb@redhat.com>
+
+       * gtk/gtktreemodel.c (gtk_tree_model_foreach): New function to
+       walk through a model in a depth first manner, with the option to
+       break out.
+
 Fri Jun  8 18:52:10 2001  Jonathan Blandford  <jrb@redhat.com>
 
        * gtk/gtktreeview.[hc]: Patch Thomas Broyer from
index f91763772016bd877553388bf48f3db8b86b21fd..f557ba76fbebdd7443031dbf934c8af23064859d 100644 (file)
@@ -1,3 +1,9 @@
+Fri Jun 29 00:13:34 2001  Jonathan Blandford  <jrb@redhat.com>
+
+       * gtk/gtktreemodel.c (gtk_tree_model_foreach): New function to
+       walk through a model in a depth first manner, with the option to
+       break out.
+
 Fri Jun  8 18:52:10 2001  Jonathan Blandford  <jrb@redhat.com>
 
        * gtk/gtktreeview.[hc]: Patch Thomas Broyer from
index f91763772016bd877553388bf48f3db8b86b21fd..f557ba76fbebdd7443031dbf934c8af23064859d 100644 (file)
@@ -1,3 +1,9 @@
+Fri Jun 29 00:13:34 2001  Jonathan Blandford  <jrb@redhat.com>
+
+       * gtk/gtktreemodel.c (gtk_tree_model_foreach): New function to
+       walk through a model in a depth first manner, with the option to
+       break out.
+
 Fri Jun  8 18:52:10 2001  Jonathan Blandford  <jrb@redhat.com>
 
        * gtk/gtktreeview.[hc]: Patch Thomas Broyer from
index f91763772016bd877553388bf48f3db8b86b21fd..f557ba76fbebdd7443031dbf934c8af23064859d 100644 (file)
@@ -1,3 +1,9 @@
+Fri Jun 29 00:13:34 2001  Jonathan Blandford  <jrb@redhat.com>
+
+       * gtk/gtktreemodel.c (gtk_tree_model_foreach): New function to
+       walk through a model in a depth first manner, with the option to
+       break out.
+
 Fri Jun  8 18:52:10 2001  Jonathan Blandford  <jrb@redhat.com>
 
        * gtk/gtktreeview.[hc]: Patch Thomas Broyer from
index f91763772016bd877553388bf48f3db8b86b21fd..f557ba76fbebdd7443031dbf934c8af23064859d 100644 (file)
@@ -1,3 +1,9 @@
+Fri Jun 29 00:13:34 2001  Jonathan Blandford  <jrb@redhat.com>
+
+       * gtk/gtktreemodel.c (gtk_tree_model_foreach): New function to
+       walk through a model in a depth first manner, with the option to
+       break out.
+
 Fri Jun  8 18:52:10 2001  Jonathan Blandford  <jrb@redhat.com>
 
        * gtk/gtktreeview.[hc]: Patch Thomas Broyer from
index f91763772016bd877553388bf48f3db8b86b21fd..f557ba76fbebdd7443031dbf934c8af23064859d 100644 (file)
@@ -1,3 +1,9 @@
+Fri Jun 29 00:13:34 2001  Jonathan Blandford  <jrb@redhat.com>
+
+       * gtk/gtktreemodel.c (gtk_tree_model_foreach): New function to
+       walk through a model in a depth first manner, with the option to
+       break out.
+
 Fri Jun  8 18:52:10 2001  Jonathan Blandford  <jrb@redhat.com>
 
        * gtk/gtktreeview.[hc]: Patch Thomas Broyer from
index f91763772016bd877553388bf48f3db8b86b21fd..f557ba76fbebdd7443031dbf934c8af23064859d 100644 (file)
@@ -1,3 +1,9 @@
+Fri Jun 29 00:13:34 2001  Jonathan Blandford  <jrb@redhat.com>
+
+       * gtk/gtktreemodel.c (gtk_tree_model_foreach): New function to
+       walk through a model in a depth first manner, with the option to
+       break out.
+
 Fri Jun  8 18:52:10 2001  Jonathan Blandford  <jrb@redhat.com>
 
        * gtk/gtktreeview.[hc]: Patch Thomas Broyer from
index 34c872666f9c5dd550149e284ac6ddc8254e8153..a2936830a666193a4f76c9960e2b6b65f2613be9 100644 (file)
@@ -1116,6 +1116,61 @@ gtk_tree_model_reordered (GtkTreeModel *tree_model,
 }
 
 
+static gboolean
+gtk_tree_model_foreach_helper (GtkTreeModel            *model,
+                              GtkTreeIter             *iter,
+                              GtkTreePath             *path,
+                              GtkTreeModelForeachFunc  func,
+                              gpointer                 user_data)
+{
+  gtk_tree_path_append_index (path, 0);
+
+  do
+    {
+      GtkTreeIter child;
+
+      if (gtk_tree_model_iter_children (model, &child, iter))
+       {
+         if (gtk_tree_model_foreach_helper (model, &child, path, func, user_data))
+           return TRUE;
+       }
+
+      if ((* func) (model, path, iter, user_data))
+       return TRUE;
+
+      gtk_tree_path_next (path);
+    }
+  while (gtk_tree_model_iter_next (model, iter));
+
+  gtk_tree_path_up (path);
+  return FALSE;
+}
+
+/**
+ * gtk_tree_model_foreach:
+ * @model: A #GtkTreeModel
+ * @func: A function to be called on each row
+ * @user_data: User data to passed to func.
+ * 
+ * Calls func on each node in model in a depth-first fashion.  If func returns
+ * %TRUE, then the tree ceases to be walked, and gtk_tree_model_foreach returns.
+ **/
+
+void
+gtk_tree_model_foreach (GtkTreeModel            *model,
+                       GtkTreeModelForeachFunc  func,
+                       gpointer                 user_data)
+{
+  GtkTreePath *path;
+  GtkTreeIter iter;
+
+  path = gtk_tree_path_new_root ();
+  gtk_tree_model_get_iter (model, &iter, path);
+  gtk_tree_model_foreach_helper (model, &iter, path, func, user_data);
+  gtk_tree_path_free (path);
+}
+
+
 /*
  * GtkTreeRowReference
  */
@@ -1520,3 +1575,4 @@ gtk_tree_row_reference_reordered (GObject     *proxy,
   gtk_tree_row_ref_reordered_callback (NULL, path, iter, new_order, proxy);
 }
   
+
index 37555fb3c5b24e2097732325d4d196333470da05..e4549f0f87ca5458413e852de121e5ab317d0398 100644 (file)
@@ -36,6 +36,7 @@ typedef struct _GtkTreePath         GtkTreePath;
 typedef struct _GtkTreeRowReference GtkTreeRowReference;
 typedef struct _GtkTreeModel        GtkTreeModel; /* Dummy typedef */
 typedef struct _GtkTreeModelIface   GtkTreeModelIface;
+typedef gboolean (* GtkTreeModelForeachFunc) (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data);
 
 
 typedef enum
@@ -215,6 +216,11 @@ void              gtk_tree_model_get_valist      (GtkTreeModel *tree_model,
                                                  va_list       var_args);
 
 
+void              gtk_tree_model_foreach         (GtkTreeModel            *model,
+                                                 GtkTreeModelForeachFunc  func,
+                                                 gpointer                 user_data);
+
+
 /* Signals */
 void gtk_tree_model_range_changed     (GtkTreeModel *tree_model,
                                       GtkTreePath  *start_path,